﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Users;

namespace EcoSystem
{
    /// <summary>
    /// 当前登录用户信息上下文件扩展信息获取
    /// </summary>
    public static class CurrentUserExtensions
    {
        public static string GetAvatar(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue(ExtraClaimNames.Avatar);
        }

        /// <summary>
        /// 获取当前用户机构编码
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public static string GetOrganizeCode(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue(ExtraClaimNames.OrganizeCode);
        }

        /// <summary>
        /// 获取当前机构ID
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public static string GetOrganizeId(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue(ExtraClaimNames.OrganizeId);
        }

        /// <summary>
        /// 获取当前客户端ID
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public static string GetClientId(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue(ExtraClaimNames.ClientId);
        }

        /// <summary>
        /// 获取当前账号所属企业
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public static Nullable<Guid> GetEnterpriseId(this ICurrentUser currentUser)
        {
            var id = currentUser.FindClaimValue(ExtraClaimNames.EnterpriseId);
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            else
            {
                return Guid.Parse(id);
            }
        }

        /// <summary>
        /// 获取当前账号所属区域
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public static string GetRegionCode(this ICurrentUser currentUser)
        {
            return currentUser.FindClaimValue(ExtraClaimNames.RegionCode);
        }
    }

}
